package com.hanxu.mallsearch.controller;

import com.hanxu.common.exception.BizCodeEnum;
import com.hanxu.common.to.es.SkuEsModel;
import com.hanxu.common.utils.R;
import com.hanxu.mallsearch.service.ProductSaveService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.math.BigDecimal;
import java.util.List;
@Slf4j
@RequestMapping("/mallsearch")
@RestController
public class ElasticSaveController {
    @Autowired
    ProductSaveService productSaveService;

    // 上架商品
    @PostMapping("save/product")
    public R productStatusUp(@RequestBody List<SkuEsModel> skuEsModelList)  {
        boolean flag = false;
        try{
            flag=productSaveService.productStatusUp(skuEsModelList);
        }catch (Exception e){
            log.error("商品上架错误:{}",e.getMessage());
            return R.error(BizCodeEnum.PRODUCT_UP_EXCEPTION.getCode(), BizCodeEnum.PRODUCT_UP_EXCEPTION.getMsg());
        }
        if(flag){
            return R.error(BizCodeEnum.PRODUCT_UP_EXCEPTION.getCode(), BizCodeEnum.PRODUCT_UP_EXCEPTION.getMsg());
        }
        return R.ok();
    }
}
